﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ParallelRuntimeLibrary;
using System.Threading;
using System.Diagnostics;

namespace TestProject
{
    public static class CountdownEventTest
    {
        public static void Test()
        {
            CountdownEvent x = new CountdownEvent(3);

            Action<object> act = new Action<object>(obj =>
            {

                for (int i = 0; i < 10000000; i++)
                {
                    int lo = Thread.CurrentThread.ManagedThreadId;
                }

                x.Signal();
            });

            Task[] Ts = new Task[4];
            for (int i = 0; i < Ts.Length; i++)
            {
                Ts[i] = new Task(act, null);
            }

            
            TaskManager.Start(Ts);
            x.Wait();
            Console.WriteLine("x count : " + x.CurrentCount);
            Console.WriteLine("x count : " + x.IsSet);
            Console.ReadLine();
        }

        public static void HPDTest()
        {
            long total = 0;

            for (int o = 0; o < 10; o++)
            {
                Stopwatch sw = Stopwatch.StartNew();

                ParallelRuntimeLibrary.HPDispatcher.Parallel.For<string>(0, 100000000, false, ThreadPriority.Normal, () => { return null; }, 
                    (i, pls, str) =>
                    {
                        int T = Thread.CurrentThread.ManagedThreadId;
                    });

                total += sw.ElapsedMilliseconds;
                sw.Stop();
                Console.WriteLine("Time : " + sw.ElapsedMilliseconds);
                Thread.Sleep(291);
            }

            Console.WriteLine("Ava : " + total / 10);

        }

        public static void LoopTest()
        {
            Console.ReadLine();
            long total = 0;

            Parallel.For(0, 10000, i =>
            {
                int T = Thread.CurrentThread.ManagedThreadId;
            });

            for (int o = 0; o < 10; o++)
            {
                Stopwatch sw = Stopwatch.StartNew();

                Parallel.For(0, 100000000, i =>
                    {
                        int T = Thread.CurrentThread.ManagedThreadId;
                    });

                total += sw.ElapsedMilliseconds;
                sw.Stop();
                Console.WriteLine("Time : " + sw.ElapsedMilliseconds);
                Thread.Sleep(291);
            }

            Console.WriteLine("Ava : " + total / 10);

        }


    }
}
